package com.harry.resource.workflow.entity;

import javax.persistence.*;
import java.util.Set;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import com.harry.basis.BasePoEntity;
import static com.harry.configuration.ConstSettings.*;
import lombok.*;

@Getter
@Setter
@Entity
public class WorkFlowInstance extends BasePoEntity {

	private static final long serialVersionUID = 1L;

	@Column(length = SHORT_LENGTH, updatable = false, nullable = false)
	private String name;

	@Fetch(FetchMode.JOIN)
	@ManyToOne(cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
	@JoinColumn(nullable = false, updatable = false)
	private WorkFlowDefinition flowDefinition;

	@Fetch(FetchMode.JOIN)
	@OneToMany(cascade = CascadeType.REMOVE, fetch = FetchType.LAZY)
	@JoinColumn
	private Set<WorkFlowVariable> flowVariables;

	@Fetch(FetchMode.JOIN)
	@OneToOne(cascade = CascadeType.REMOVE, fetch = FetchType.LAZY)
	@JoinColumn
	private WorkStateInstance currentWorkStateInstance;

	@Fetch(FetchMode.JOIN)
	@OneToMany(cascade = CascadeType.REMOVE, fetch = FetchType.LAZY)
	@JoinColumn
	private Set<WorkStateInstance> stateInstances;
}
